#define MAINSCENE_API __declspec(dllexport)

#include "StdAfx.h"
#include "Environment.h"



CEnvironment::CEnvironment(LPCTSTR Texture)
	:Tex(Texture, GL_Tex_BMP, 0)
{

}

CEnvironment::CEnvironment()
	:Tex("dixing.bmp", GL_Tex_BMP, 0)
{
	OrgX       = 0.0;
	OrgY       = -1.0;
	OrgZ       = -15;
}

CEnvironment::~CEnvironment(void)
{

}


void CEnvironment::Compass()
{
	glDisable(GL_LIGHTING);
	glBegin(GL_TRIANGLES);
	glColor3f(1.0f, 0.0f, 0.0f);
	glVertex3f(0.5, 0.0, 0.0);
	glVertex3f(-0.5, 0.0, 0.0);
	glVertex3f(0.0, 2.0, 0.0);
	glColor3f(1.0, 1.0, 1.0);
	glVertex3f(0.5, 0.0, 0.0);
	glVertex3f(-0.5, 0.0, 0.0);
	glVertex3f(0.0, -2.0, 0.0);
	glEnd();
	//glEnable(GL_LIGHTING);
}



void CEnvironment::Coordinate()
{
	glDisable(GL_LIGHTING);
	glBegin(GL_LINES);
	//"Z"
	glColor3f(1.0, 0.0, 0.0);
	glVertex3f(0.0, 1.0, 0.0);
	glVertex3f(0.0, 0.0, 0.0);
	glVertex3f(0.0, 1.0, 0.0);
	glVertex3f(-0.2, 0.8, 0.0);
	glVertex3f(0.0, 1.0, 0.0);
	glVertex3f(0.2, 0.8, 0.0);

	//"X"
	glColor3f(0.0, 1.0, 0.0);
	glVertex3f(1.0, 0.0, 0.0);
	glVertex3f(0.0, 0.0, 0.0);
	glVertex3f(0.8, 0.2, 0.0);
	glVertex3f(1.0, 0.0, 0.0);
	glVertex3f(0.8, -0.2, 0.0);
	glVertex3f(1.0, 0.0, 0.0);

	//"Y"
	glColor3f(1.0, 1.0, 1.0);
	glVertex3f(0.0, 0.0,-1.0);
	glVertex3f(0.0, 0.0, 0.0);
	glVertex3f(0.2, 0.0, -1.0);
	glVertex3f(0.0, 0.0, -1.0);
	glVertex3f(-0.2, 0.0, 0.0);
	glVertex3f(0.0, 0.0, -1.0);
	glEnd();
	glEnable(GL_LIGHTING);
}



void CEnvironment::DrawCompass()
{
	glPushMatrix();
	glRasterPos3f(-1.7, 1.25, -7.5);
	glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, 'N');
	glRasterPos3f(-1.7, 1.1, -7.5);
	glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, 'S');
	glTranslatef(-1.8, 1.2, -7.5);
	glScalef(0.08, 0.05, 0.0);
	Compass();
	glPopMatrix();
}



void CEnvironment::DrawCoordinate()
{
	glPushMatrix();
	glRasterPos3f(1.55, 1.2, -7.5);
	glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, 'Y');
	glRasterPos3f(1.65, 1.05, -7.5);
	glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, 'X');
	glRasterPos3f(1.50, 1.05, -8.0);
	glutBitmapCharacter(GLUT_BITMAP_HELVETICA_10, 'Z');
	glTranslatef(1.5, 1.0, -7.5);
	glScalef(0.2, 0.2, 0.2);
	Coordinate();
	glPopMatrix();
}



void CEnvironment::RenderScene()
{
	glDisable(GL_LIGHTING);
	CTexture::Enable(true);
	Tex.Apply();
	glBegin(GL_QUADS);
	glTexCoord2f(0.0, 1.0);
	glVertex3f(-6.0, 0.0, -4.0);

	glTexCoord2f(0.0, 0.0);
	glVertex3f(-6.0, 0.0, 4.0);

	glTexCoord2f(1.0, 0.0);
	glVertex3f(6.0, 0.0, 4.0);

	glTexCoord2f(1.0, 1.0);
	glVertex3f(6.0, 0.0, -4.0);
	glEnd();

	CTexture::Enable(false);
	glEnable(GL_LIGHTING);
}



void CEnvironment::DrawMap()
{
	glPushMatrix();
	glTranslatef(OrgX, OrgY, OrgZ);
	glRotatef(-90, 1.0, 0.0, 0.0);
	RenderScene();
	glPopMatrix();
}

void CEnvironment::Up()
{
	OrgZ -= 0.01;
}


void CEnvironment::Down()
{
	OrgZ += 0.01;
}

void CEnvironment::Left()
{
	OrgX -= 0.01;
}

void CEnvironment::Right()
{
	OrgX += 0.01;
}


void CEnvironment::W()
{
	OrgY -= 0.01;
}


void CEnvironment::S()
{
	OrgY += 0.01;
}


